package commonUtils.config;



import commonUtils.utils.LoginInterceptor;
import commonUtils.utils.ReflashInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //刷新有效期，token拦截器
        registry.addInterceptor(new ReflashInterceptor(stringRedisTemplate))
                .addPathPatterns("/**");
        //登录校验，登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        //指定不拦截的路径
//                        "/shop/**",
//                        "/voucher/**",
//                        "/shop-type/**",
//                        "/upload/**",
//                        "/blog/hot",
//                        "/user/code",
//                        "/user/login"
                );
    }
}
